package main

import (
	"context"
	"fmt"
	"github.com/coreos/etcd/clientv3"
	"time"
)

/**
开启命令
  etcd --config-file config.yaml
*/
func main() {
	var (
		config clientv3.Config
		err    error
		client *clientv3.Client
	)
	//配置
	config = clientv3.Config{
		Endpoints:   []string{"192.168.0.104:2379"},
		DialTimeout: time.Second * 5,
	}
	//连接 床见一个客户端
	if client, err = clientv3.New(config); err != nil {
		fmt.Println(err)
		return
	}
	ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
	//用于读写etcd的键值对
	_, err = client.Put(ctx, "/cron", "byt")
	if err != nil {
		fmt.Println(err)
		return
	}
	res, err := client.Get(ctx, "/cron/jobs/job1")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(*res)
}
